package db

import (
	"github.com/jinzhu/gorm"
)

type IMSlave struct {
	gorm.Model

	SmallId uint
	BigId   uint
	Status  int
}

func (s *IMSlave) Save() {
	dbIns.Save(s)
}

func (s *IMSlave) Delete() {
	dbIns.Delete(s)
}

func (s *IMSlave) CheckHave(smallId, bigId uint, status int) (relateId uint) {
	if smallId > bigId {
		smallId, bigId = bigId, smallId
	}

	model := &IMSlave{}
	dbIns.Where("small_id=? and big_id=? and status=?", smallId, bigId, status).First(model)

	if model.ID == 0 {
		model.SmallId = smallId
		model.BigId = bigId
		model.Status = status
		dbIns.Save(model)
	}
	relateId = model.ID
	return
}
